package com.qf.web.servlet;

import com.qf.pojo.Emp;
import com.qf.service.EmpService;
import com.qf.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * 动物 dw = new 狗()
 *
 * 狗 g = (狗)dw;
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/updateEmp")
public class UpdateEmpServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String name = req.getParameter("name");
        String salary = req.getParameter("salary");
        String age = req.getParameter("age");
        Emp emp = new Emp();
        emp.setId(Integer.parseInt(id));
        emp.setName(name);
        emp.setSalary(Double.parseDouble(salary));
        emp.setAge(Integer.parseInt(age));
        EmpService service = new EmpServiceImpl();
        //修改的业务
        service.update(emp);
        //重定向 查询所有员工
        resp.sendRedirect("/selectAllEmp");

    }

}
